<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li class="active">角色管理</li>
			</ul>
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>角色管理
					<small>
					<i class="icon-double-angle-right"></i>
					查看
					</small>					
				</h1>			
			</div>
			<div class="row">
				<div class="col-xs-12">
				<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
						<thead>
								<tr>
									<th class="center" style="width: 30px;">
										<label><input class="ace" type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									<th class='center' style="width:50px;">序号</th>
									<th class="left">角色名</th>
									<th class="left">操作</th>
								</tr>
						</thead>
						<tbody id="rolelist">
						
						<c:forEach var="res" items="${res.data.rows}" varStatus="status">
						
							<tr  id="userinfo_row_${res.role_id}" >
									<td class="center">
										<label><input type="checkbox" class="ace" /><span class="lbl"></span></label>
									</td>
									<td class='center' >${ status.index + 1}</td>  		
									<td>&nbsp;${res.roleName}</td>
									<td>
										<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
											<button class="btn btn-xs btn-info" onclick="location='${ctx}/sys/role/toUpdate/${res.role_id}' ">
												<i class="icon-edit bigger-120"></i>
											</button>	
											
											<button class="btn btn-xs btn-danger" onclick="javascript:deleteRole('${res.role_id}');">
												<i class="icon-trash bigger-120"></i>
											</button>					
										</div>

									</td>
							</tr>
						
						</c:forEach>
						
						</tbody>
				</table>
				
				<div>
					<a class="btn btn-sm btn-success" href="${ctx}/sys/role/toAdd">新增角色</a>
				</div>
				
				</div>
				</div>
			</div>
			<script type="text/javascript">
			jQuery(function($) {
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
			})
			
			function deleteRole(roleId){
				//alert(roleId)
				if(confirm("确认删除该条用户信息？")){
					var roleData = new Object();
					roleData.role_id = roleId;
					$.ajax({
				        async: true,
				        type:"POST",
				        data:roleData,
				        url: "${ctx}/sys/role/delete/"+roleId,
				        dataType: "json",
				        success: function (data) {
				    	    if(0 == data.status){//成功
				    	    	alert("删除成功");
				    	    	window.location.href = "${ctx}/sys/role/listRole";
				    	    }else{//失败
				    	    	alert(data.error);
				    	    }
				        }
					},"json");
					
				}
			}
			</script>
	</body>
	
</html>
